package com.example.myapplication.ui.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.myapplication.R;
import com.example.myapplication.base.BaseLazyFragment;
import com.example.myapplication.bean.NavigationBean;
import com.example.myapplication.presenter.NavigationPresenter;
import com.example.myapplication.ui.adapter.NavigationAdapter;
import com.example.myapplication.view.NavigationView;

import java.util.ArrayList;
import java.util.List;

import qdx.stickyheaderdecoration.NormalDecoration;

/**
 * 导航
 */
public class NavigationFragment extends BaseLazyFragment<NavigationPresenter> implements NavigationView {


    private RecyclerView rv;
    private NavigationAdapter navigationAdapter;

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getNavigationData();
    }

    @Override
    protected void initView(View view) {
        rv = (RecyclerView) view.findViewById(R.id.rv);
        rv.setLayoutManager(new LinearLayoutManager(getContext()));
        final ArrayList<NavigationBean.DataBean> list = new ArrayList<>();
        navigationAdapter = new NavigationAdapter(getActivity(),list);
        rv.setAdapter(navigationAdapter);
        NormalDecoration normalDecoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int i) {
                return list.get(i).getName();
            }
        };
        rv.addItemDecoration(normalDecoration);
    }

    @Override
    protected NavigationPresenter initPresenter() {
        return new NavigationPresenter();
    }


    @Override
    protected int getLayout() {
        return R.layout.fragment_navigation;
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void setData(NavigationBean navigationBean) {
        List<NavigationBean.DataBean> data = navigationBean.getData();
        navigationAdapter.addData(data);
    }
}